package com.bg.sparkproject.dao.impl;

import com.bg.sparkproject.dao.TaskDao;
import com.bg.sparkproject.domain.Task;
import com.bg.sparkproject.utils.JDBCHelper;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Auther: zhengshunzhi
 * @Date: 2018/12/19 14:47
 * @Description:
 */
public class TaskDaoImpl implements TaskDao {

    private static JDBCHelper jdbcHelper = JDBCHelper.getInstance();

    @Override
    public Task findById(long taskId) {
        String sql = "select * from task where task_id = ?";
        Object[] params = new Object[]{1};
        final Task task = new Task();
        jdbcHelper.excuteQuery(sql, params, new JDBCHelper.QueryCallBack() {
            @Override
            public void process(ResultSet rst) throws SQLException {
                while (rst.next()) {
                    long taskId = rst.getLong(1);
                    String taskName = rst.getString(2);
                    String createTime = rst.getString(3);
                    String startTime = rst.getString(4);
                    String finishTime = rst.getString(5);
                    String taskType = rst.getString(6);
                    String taskStatus = rst.getString(7);
                    String taskParam = rst.getString(8);

                    task.setTaskId(taskId);
                    task.setTaskName(taskName);
                    task.setCreateTime(createTime);
                    task.setStartTime(startTime);
                    task.setFinishTime(finishTime);
                    task.setTaskType(taskType);
                    task.setTaskStatus(taskStatus);
                    task.setTaskParam(taskParam);
                }
            }
        });
        return task;
    }
}
